# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Sören Tempel <soeren+alpine@soeren-tempel.net>
pkgname=ormolu
pkgver=0.7.7.0
pkgrel=0
pkgdesc="Formatter for Haskell source code"
url="https://github.com/tweag/ormolu"
arch="x86_64 aarch64" # limited by ghc
license="BSD-3-Clause"
makedepends="ghc cabal"
options="net"
subpackages="$pkgname-doc"
source="https://hackage.haskell.org/package/ormolu-$pkgver/ormolu-$pkgver.tar.gz
	cabal.project.freeze"

# Directory were cabal files are stored.
export CABAL_DIR="$srcdir/dist"

# Needed to fix build on aarch64.
export PATH="$PATH:/usr/lib/llvm15/bin"

cabal_update() {
	cd $builddir
	cabal v2-update
	(
		cd "$builddir"
		cabal v2-freeze --shadow-installed-packages
		mv cabal.project.freeze "$startdir/"
	)
}

prepare() {
	default_prepare
	ln -sf "$srcdir/cabal.project.freeze" \
		"$builddir/cabal.project.freeze"
}

build() {
	cabal v2-update
	cabal v2-build ormolu:exes \
		--jobs=${JOBS:-1} \
		--prefix=/usr \
		--docdir=/usr/share/doc/$pkgname \
		--sysconfdir=/etc
}

check() {
	cabal test
}

package() {
	# See https://github.com/haskell/cabal/issues/6919#issuecomment-761563498
	cabal list-bin ormolu:exes | xargs install -Dm755 -t "$pkgdir"/usr/bin

	# Install some docmuentation files
	mkdir -p "$pkgdir"/usr/share/doc/$pkgname
	install -m644 README.md CHANGELOG.md DESIGN.md \
		"$pkgdir"/usr/share/doc/$pkgname
}

sha512sums="
b0f2e889dbffb06b753f80409cc6792dc0c2d9e26c8e6a38f6b673d55be7395586b8497347f00652608ba16d482464906373791f6424bc4d4ddb8ed607a0b824  ormolu-0.7.7.0.tar.gz
6258affb9db3f132a1fbc2310827bcb9de54ba8e039d4eec1fa055b8ed824a4f66d4992b6f38f113000f453c904a128dfe90b7c0b1f75a580e4f2a0dd4709704  cabal.project.freeze
"
